<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="用户名称" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学号/工号" prop="userNumber">
        <el-input
          v-model="queryParams.userNumber"
          placeholder="请输入学号或工号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户类型" prop="userType">
        <el-select v-model="queryParams.userType" placeholder="请选择用户类型" clearable>
          <el-option label="学生" value="1"/>
          <el-option label="教师" value="2"/>
          <el-option label="家长" value="3"/>
          <el-option label="学校管理员" value="4"/>
        </el-select>
      </el-form-item>
      <el-form-item label="所属学校" prop="schoolId">
        <el-select v-model="queryParams.schoolId" placeholder="请选择学校" clearable filterable>
          <el-option
            v-for="school in schoolList"
            :key="school.schoolId"
            :label="school.schoolName"
            :value="school.schoolId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="微信绑定" prop="wechatBound">
        <el-select v-model="queryParams.wechatBound" placeholder="微信绑定状态" clearable>
          <el-option label="已绑定" :value="true"/>
          <el-option label="未绑定" :value="false"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 用户统计 -->
    <el-row :gutter="20" class="mb8">
      <el-col :span="6">
        <el-card class="stat-card student">
          <div class="stat-content">
            <div class="stat-number">{{ userStats.studentCount }}</div>
            <div class="stat-label">学生用户</div>
          </div>
          <div class="stat-icon">
            <i class="el-icon-user"></i>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="stat-card teacher">
          <div class="stat-content">
            <div class="stat-number">{{ userStats.teacherCount }}</div>
            <div class="stat-label">教师用户</div>
          </div>
          <div class="stat-icon">
            <i class="el-icon-user-solid"></i>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="stat-card parent">
          <div class="stat-content">
            <div class="stat-number">{{ userStats.parentCount }}</div>
            <div class="stat-label">家长用户</div>
          </div>
          <div class="stat-icon">
            <i class="el-icon-s-custom"></i>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="stat-card wechat">
          <div class="stat-content">
            <div class="stat-number">{{ userStats.wechatBoundCount }}</div>
            <div class="stat-label">微信绑定</div>
          </div>
          <div class="stat-icon">
            <i class="el-icon-chat-dot-round"></i>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['campus:user:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['campus:user:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['campus:user:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['campus:user:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-link"
          size="mini"
          @click="handleBatchBind"
          v-hasPermi="['campus:user:bind']"
        >批量绑定学校</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户名" align="center" prop="userName" width="120"/>
      <el-table-column label="昵称" align="center" prop="nickName" width="120" :show-overflow-tooltip="true"/>
      <el-table-column label="用户类型" align="center" prop="userType" width="100">
        <template slot-scope="scope">
          <el-tag :type="getUserTypeTagType(scope.row.userType)">
            {{ getUserTypeName(scope.row.userType) }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="学号/工号" align="center" width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.userType === 1">{{ scope.row.studentNumber || '-' }}</span>
          <span v-else-if="scope.row.userType === 2">{{ scope.row.teacherNumber || '-' }}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="所属学校" align="center" prop="schoolName" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="班级" align="center" prop="className" width="120" :show-overflow-tooltip="true"/>
      <el-table-column label="手机号码" align="center" prop="phonenumber" width="120"/>
      <el-table-column label="微信绑定" align="center" width="100">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.wechatBound" type="success" size="mini">已绑定</el-tag>
          <el-tag v-else type="info" size="mini">未绑定</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(scope.row)"
            v-hasPermi="['campus:user:query']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['campus:user:edit']"
          >修改</el-button>
          <el-button
            v-if="!scope.row.schoolId"
            size="mini"
            type="text"
            icon="el-icon-link"
            @click="handleBind(scope.row)"
            v-hasPermi="['campus:user:bind']"
          >绑定学校</el-button>
          <el-dropdown @command="(command) => handleMoreAction(command, scope.row)">
            <span class="el-dropdown-link">
              更多<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="resetPwd" icon="el-icon-key">重置密码</el-dropdown-item>
              <el-dropdown-item command="delete" icon="el-icon-delete">删除</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改用户扩展信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="用户类型" prop="userType">
              <el-select v-model="form.userType" placeholder="请选择用户类型" style="width: 100%" @change="handleUserTypeChange">
                <el-option label="学生" :value="1"/>
                <el-option label="教师" :value="2"/>
                <el-option label="家长" :value="3"/>
                <el-option label="学校管理员" :value="4"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属学校" prop="schoolId">
              <el-select v-model="form.schoolId" placeholder="请选择学校" style="width: 100%" filterable>
                <el-option
                  v-for="school in schoolList"
                  :key="school.schoolId"
                  :label="school.schoolName"
                  :value="school.schoolId"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="form.userType === 1">
          <el-col :span="12">
            <el-form-item label="学号" prop="studentNumber">
              <el-input v-model="form.studentNumber" placeholder="请输入学号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="班级" prop="classId">
              <el-select v-model="form.classId" placeholder="请选择班级" style="width: 100%">
                <el-option label="一年级1班" :value="1"/>
                <el-option label="一年级2班" :value="2"/>
                <!-- 这里应该动态加载班级列表 -->
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="form.userType === 2">
          <el-col :span="12">
            <el-form-item label="工号" prop="teacherNumber">
              <el-input v-model="form.teacherNumber" placeholder="请输入工号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="身份证号" prop="idCard">
              <el-input v-model="form.idCard" placeholder="请输入身份证号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出生日期" prop="birthday">
              <el-date-picker
                v-model="form.birthday"
                type="date"
                placeholder="选择出生日期"
                value-format="yyyy-MM-dd"
                style="width: 100%">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="性别" prop="gender">
              <el-select v-model="form.gender" placeholder="请选择性别" style="width: 100%">
                <el-option label="男" :value="1"/>
                <el-option label="女" :value="2"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="家长电话" prop="parentPhone">
              <el-input v-model="form.parentPhone" placeholder="请输入家长电话" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="紧急联系人" prop="emergencyContact">
              <el-input v-model="form.emergencyContact" placeholder="请输入紧急联系人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="紧急联系电话" prop="emergencyPhone">
              <el-input v-model="form.emergencyPhone" placeholder="请输入紧急联系电话" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="家庭地址" prop="address">
          <el-input v-model="form.address" type="textarea" placeholder="请输入家庭地址" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 用户详情对话框 -->
    <el-dialog title="用户详情" :visible.sync="detailOpen" width="1000px" append-to-body>
      <el-descriptions :column="2" border>
        <el-descriptions-item label="用户名">{{ detailForm.userName }}</el-descriptions-item>
        <el-descriptions-item label="昵称">{{ detailForm.nickName }}</el-descriptions-item>
        <el-descriptions-item label="用户类型">{{ getUserTypeName(detailForm.userType) }}</el-descriptions-item>
        <el-descriptions-item label="手机号码">{{ detailForm.phonenumber }}</el-descriptions-item>
        <el-descriptions-item label="邮箱">{{ detailForm.email }}</el-descriptions-item>
        <el-descriptions-item label="所属学校">{{ detailForm.schoolName }}</el-descriptions-item>
        <el-descriptions-item label="学号" v-if="detailForm.userType === 1">{{ detailForm.studentNumber }}</el-descriptions-item>
        <el-descriptions-item label="工号" v-if="detailForm.userType === 2">{{ detailForm.teacherNumber }}</el-descriptions-item>
        <el-descriptions-item label="班级" v-if="detailForm.userType === 1">{{ detailForm.className }}</el-descriptions-item>
        <el-descriptions-item label="身份证号">{{ detailForm.idCard }}</el-descriptions-item>
        <el-descriptions-item label="出生日期">{{ detailForm.birthday }}</el-descriptions-item>
        <el-descriptions-item label="性别">{{ detailForm.gender === 1 ? '男' : detailForm.gender === 2 ? '女' : '未知' }}</el-descriptions-item>
        <el-descriptions-item label="年龄">{{ detailForm.age }}</el-descriptions-item>
        <el-descriptions-item label="家长电话">{{ detailForm.parentPhone }}</el-descriptions-item>
        <el-descriptions-item label="紧急联系人">{{ detailForm.emergencyContact }}</el-descriptions-item>
        <el-descriptions-item label="紧急联系电话">{{ detailForm.emergencyPhone }}</el-descriptions-item>
        <el-descriptions-item label="微信绑定">
          <el-tag :type="detailForm.wechatBound ? 'success' : 'info'">
            {{ detailForm.wechatBound ? '已绑定' : '未绑定' }}
          </el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="家庭地址" :span="2">{{ detailForm.address }}</el-descriptions-item>
        <el-descriptions-item label="创建时间">{{ detailForm.createTime }}</el-descriptions-item>
        <el-descriptions-item label="更新时间">{{ detailForm.updateTime }}</el-descriptions-item>
        <el-descriptions-item label="备注" :span="2">{{ detailForm.remark }}</el-descriptions-item>
      </el-descriptions>
    </el-dialog>

    <!-- 绑定学校对话框 -->
    <el-dialog title="绑定学校" :visible.sync="bindOpen" width="500px" append-to-body>
      <el-form ref="bindForm" :model="bindForm" label-width="100px">
        <el-form-item label="选择学校" prop="schoolId">
          <el-select v-model="bindForm.schoolId" placeholder="请选择学校" style="width: 100%" filterable>
            <el-option
              v-for="school in schoolList"
              :key="school.schoolId"
              :label="school.schoolName"
              :value="school.schoolId"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitBind">确 定</el-button>
        <el-button @click="bindOpen = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 批量绑定学校对话框 -->
    <el-dialog title="批量绑定学校" :visible.sync="batchBindOpen" width="500px" append-to-body>
      <el-form ref="batchBindForm" :model="batchBindForm" label-width="100px">
        <el-form-item label="选择学校" prop="schoolId">
          <el-select v-model="batchBindForm.schoolId" placeholder="请选择学校" style="width: 100%" filterable>
            <el-option
              v-for="school in schoolList"
              :key="school.schoolId"
              :label="school.schoolName"
              :value="school.schoolId"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="已选用户">
          <span>{{ selectedUsers.length }}个用户</span>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitBatchBind">确 定</el-button>
        <el-button @click="batchBindOpen = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { 
  listUserExtend, 
  getUserExtendDetail, 
  addUserExtend, 
  updateUserExtend, 
  delUserExtend,
  updateUserSchoolBatch,
  checkStudentNumberUnique,
  checkTeacherNumberUnique,
  getUserStatistics,
  exportUserExtend
} from "@/api/campus/userExtend";
import { listActiveSchool } from "@/api/campus/school";

export default {
  name: "UserExtend",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 选中的用户
      selectedUsers: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户扩展信息表格数据
      userList: [],
      // 学校列表
      schoolList: [],
      // 用户统计
      userStats: {
        studentCount: 0,
        teacherCount: 0,
        parentCount: 0,
        wechatBoundCount: 0
      },
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示详情弹出层
      detailOpen: false,
      // 是否显示绑定弹出层
      bindOpen: false,
      // 是否显示批量绑定弹出层
      batchBindOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: null,
        userNumber: null,
        userType: null,
        schoolId: null,
        wechatBound: null
      },
      // 表单参数
      form: {},
      // 详情表单参数
      detailForm: {},
      // 绑定表单参数
      bindForm: {},
      // 批量绑定表单参数
      batchBindForm: {},
      // 当前操作用户ID
      currentUserId: null,
      // 表单校验
      rules: {
        userType: [
          { required: true, message: "用户类型不能为空", trigger: "change" }
        ],
        schoolId: [
          { required: true, message: "所属学校不能为空", trigger: "change" }
        ],
        studentNumber: [
          { required: true, message: "学号不能为空", trigger: "blur" }
        ],
        teacherNumber: [
          { required: true, message: "工号不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
    this.getSchoolList();
    this.getUserStats();
  },
  methods: {
    /** 查询用户扩展信息列表 */
    getList() {
      this.loading = true;
      listUserExtend(this.queryParams).then(response => {
        this.userList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 获取学校列表 */
    getSchoolList() {
      listActiveSchool().then(response => {
        this.schoolList = response.data;
      });
    },
    /** 获取用户统计 */
    getUserStats() {
      getUserStatistics().then(response => {
        this.userStats = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        userId: null,
        userType: null,
        schoolId: null,
        classId: null,
        studentNumber: null,
        teacherNumber: null,
        idCard: null,
        birthday: null,
        gender: null,
        parentPhone: null,
        emergencyContact: null,
        emergencyPhone: null,
        address: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userId)
      this.selectedUsers = selection
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户扩展信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const userId = row.userId || this.ids[0]
      getUserExtendDetail(userId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改用户扩展信息";
      });
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      const userId = row.userId;
      getUserExtendDetail(userId).then(response => {
        this.detailForm = response.data;
        this.detailOpen = true;
      });
    },
    /** 绑定学校 */
    handleBind(row) {
      this.currentUserId = row.userId;
      this.bindForm = {
        schoolId: null
      };
      this.bindOpen = true;
    },
    /** 批量绑定学校 */
    handleBatchBind() {
      if (this.selectedUsers.length === 0) {
        this.$modal.msgError("请选择要绑定的用户");
        return;
      }
      this.batchBindForm = {
        schoolId: null
      };
      this.batchBindOpen = true;
    },
    /** 用户类型变化 */
    handleUserTypeChange(value) {
      // 重置相关字段
      if (value === 1) {
        this.form.teacherNumber = null;
      } else if (value === 2) {
        this.form.studentNumber = null;
        this.form.classId = null;
      }
    },
    /** 更多操作 */
    handleMoreAction(command, row) {
      switch(command) {
        case 'resetPwd':
          this.resetUserPassword(row);
          break;
        case 'delete':
          this.handleDelete(row);
          break;
      }
    },
    /** 提交表单 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // 校验学号/工号唯一性
          if (this.form.userType === 1 && this.form.studentNumber) {
            checkStudentNumberUnique(this.form.schoolId, this.form.studentNumber, this.form.userId).then(response => {
              if (response.data > 0) {
                this.$modal.msgError("该学号已存在");
                return;
              }
              this.submitUserForm();
            });
          } else if (this.form.userType === 2 && this.form.teacherNumber) {
            checkTeacherNumberUnique(this.form.schoolId, this.form.teacherNumber, this.form.userId).then(response => {
              if (response.data > 0) {
                this.$modal.msgError("该工号已存在");
                return;
              }
              this.submitUserForm();
            });
          } else {
            this.submitUserForm();
          }
        }
      });
    },
    /** 提交用户表单 */
    submitUserForm() {
      if (this.form.userId != null) {
        updateUserExtend(this.form).then(response => {
          this.$modal.msgSuccess("修改成功");
          this.open = false;
          this.getList();
        });
      } else {
        addUserExtend(this.form).then(response => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
        });
      }
    },
    /** 提交绑定 */
    submitBind() {
      if (!this.bindForm.schoolId) {
        this.$modal.msgError("请选择学校");
        return;
      }
      updateUserSchoolBatch([this.currentUserId], this.bindForm.schoolId).then(response => {
        this.$modal.msgSuccess("绑定成功");
        this.bindOpen = false;
        this.getList();
      });
    },
    /** 提交批量绑定 */
    submitBatchBind() {
      if (!this.batchBindForm.schoolId) {
        this.$modal.msgError("请选择学校");
        return;
      }
      updateUserSchoolBatch(this.ids, this.batchBindForm.schoolId).then(response => {
        this.$modal.msgSuccess("批量绑定成功");
        this.batchBindOpen = false;
        this.getList();
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const userIds = row.userId || this.ids;
      this.$modal.confirm('是否确认删除用户编号为"' + userIds + '"的数据项？').then(function() {
        return delUserExtend(userIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 重置密码 */
    resetUserPassword(row) {
      this.$modal.prompt('请输入"' + row.userName + '"的新密码', "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnClickModal: false,
        inputPattern: /^.{5,20}$/,
        inputErrorMessage: "用户密码长度必须介于 5 和 20 之间"
      }).then(({ value }) => {
        // 调用重置密码接口
        this.$modal.msgSuccess("修改成功，新密码是：" + value);
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('campus/userExtend/export', {
        ...this.queryParams
      }, `userExtend_${new Date().getTime()}.xlsx`)
    },
    /** 获取用户类型名称 */
    getUserTypeName(type) {
      const types = {
        1: '学生',
        2: '教师',
        3: '家长',
        4: '学校管理员'
      };
      return types[type] || '未知';
    },
    /** 获取用户类型标签类型 */
    getUserTypeTagType(type) {
      const types = {
        1: 'primary',
        2: 'success',
        3: 'warning',
        4: 'danger'
      };
      return types[type] || '';
    }
  }
};
</script>

<style scoped>
.stat-card {
  border: none;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
  margin-bottom: 16px;
}

.stat-card .el-card__body {
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.stat-content {
  position: relative;
  z-index: 2;
}

.stat-number {
  font-size: 32px;
  font-weight: bold;
  line-height: 1;
}

.stat-label {
  font-size: 14px;
  color: #909399;
  margin-top: 8px;
}

.stat-icon {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 48px;
  opacity: 0.2;
}

.stat-card.student .stat-number {
  color: #409EFF;
}

.stat-card.student .stat-icon {
  color: #409EFF;
}

.stat-card.teacher .stat-number {
  color: #67C23A;
}

.stat-card.teacher .stat-icon {
  color: #67C23A;
}

.stat-card.parent .stat-number {
  color: #E6A23C;
}

.stat-card.parent .stat-icon {
  color: #E6A23C;
}

.stat-card.wechat .stat-number {
  color: #909399;
}

.stat-card.wechat .stat-icon {
  color: #909399;
}

.el-dropdown-link {
  cursor: pointer;
  color: #409EFF;
}

.el-dropdown-link:hover {
  color: #66b1ff;
}
</style> 